// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CLOUDAPPENGINE_CAEMEDIACONFIG_H
#define CLOUDAPPENGINE_CAEMEDIACONFIG_H

#include <string>
#include "../cae_CPHMediaEngine/CPHMediaEngine.h"
#include "../cae_common/CaeLogConfig.h"

class CaeMediaConfig {
public:
    static CaeMediaConfig &GetInstance();
    CaeMediaConfig(const CaeMediaConfig &) = delete;
    CaeMediaConfig &operator = (const CaeMediaConfig &) = delete;

    ~CaeMediaConfig();

    void ClearMediaConfig();

    void SetVideoFrameType(const char* videoFrameType);
    std::string GetVideoFrameType();

    void SetRemoteSchedulingElbIp(const char* remoteSchedulingElbIp);
    std::string GetRemoteSchedulingElbIp();

    void SetRemoteSchedulingElbPort(const char* remoteSchedulingElbPort);
    uint32_t GetRemoteSchedulingElbPort();

    void SetEncodeType(const char* encodeType);
    uint32_t GetEncodeType();

    void SetFrameRate(const char* frameRate);
    uint32_t GetFrameRate();

    void SetBitrate(const char* bitrate, bool cmdSet);
    uint32_t GetBitrate();
    uint32_t GetCmdBitrate();

    void SetGopSize(const char* gopSize);
    uint32_t GetGopSize();

    void SetProfile(const char* profile);
    uint32_t GetProfile();

    void SetRcMode(const char* rcMode);
    uint32_t GetRcMode();

    void SetPhysicalWidth(uint32_t physicalWidth);
    uint32_t GetPhysicalWidth();

    void SetPhysicalHeight(uint32_t physicalHeight);
    uint32_t GetPhysicalHeight();

    void SetStreamWidth(const char* streamWidth);
    uint32_t GetStreamWidth();

    void SetStreamHeight(const char* streamHeight);
    uint32_t GetStreamHeight();

    void SetRepeatFps(const char* repeatFps);
    uint32_t GetRepeatFps();

    uint32_t GetAudioType();
    void SetAudioType(const char* audioType);

    uint32_t GetSampleRate();
    void SetSampleRate(const char* sampleRate);

    uint32_t GetChannels();
    void SetChannels(const char* channels);

    uint32_t GetOpusInterval();
    void SetOpusInterval(const char* opusInterval);

    uint32_t GetOpusBitrate();
    void SetOpusBitrate(const char* opusBitrate);

    char* BuildVideoJsonConfig();

    char* BuildDynamicVideoJsonConfig();

    char* BuildAudioJsonConfig();

    char* BuildResponseVideoJsonConfig();

    bool IsNeedSetPhysicalResolution() const;

    void SetNeedSetPhysicalResolution(bool needSetPhysicalResolution);

    bool IsMute() const;

    void SetMute(const char* isMute);

    void SetQuality(const char* quality);

    bool IsAutoQuality() const;

    void SetAutoQuality(const char* autoQuality);

    bool IsRemoteEncoderInfoValid();

protected:
    CaeMediaConfig();

    void InitMediaConfig();

private:
    static CaeMediaConfig *instance;

    std::string m_videoFrameType;
    std::string m_remoteSchedulingElbIp;
    uint32_t m_remoteSchedulingElbPort;
    uint32_t m_fps;
    uint32_t m_bitrate;
    uint32_t m_cmdBitrate;
    uint32_t m_gopSize;
    uint32_t m_profile;
    uint32_t m_rcMode;
    uint32_t m_physicalWidth;
    uint32_t m_physicalHeight;
    uint32_t m_streamWidth;
    uint32_t m_streamHeight;
    uint32_t m_encodeType;
    uint32_t m_repeatFps;

    uint32_t m_virtualWidthAlign;  // 用于虚拟分辨率对齐校验
    uint32_t m_virtualHeightAlign; // 用于虚拟分辨率对齐校验

    uint32_t m_audioType;
    uint32_t m_sampleRate;
    uint32_t m_channels;
    uint32_t m_opusInterval;
    uint32_t m_opusBitrate;

    bool m_needSetPhysicalResolution;
    bool m_isMute;
    bool m_autoQuality;
};
#endif // CLOUDAPPENGINE_CAEMEDIACONFIG_H